<template>
  <div class='confirmInstallInfo'>
    <el-container>
      <el-aside width="300px">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small">
          <el-form-item>
            <el-input v-model="formInline.user" placeholder="输入搜索条件"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="onSubmit">查找</el-button>
          </el-form-item>
        </el-form>
        <li v-for="item in siteList" :key="item.id">
          <i class="el-icon-location-information"></i><span style="margin-left:10px">{{item.siteName}}</span>
        </li>
      </el-aside>
      <el-main>
        <div class="header">
          <h3>{{installInfo.deviceModel}}</h3>
        </div>
        <div class="containItem">
          <div class="containItem_top">
            <img src="@/assets/images/xhlogo.png" />
            <div class="containItem_top_right">
              <div>{{installInfo.containerFileName}}</div>
            </div>
          </div>
          <div class="containItem_bottom">
            <ul>
              <li>
                <span> 容器版本： </span>
                <span>{{installInfo.containerFileVersion}}</span>
              </li>
              <li>
                <span> 容器大小： </span>
                <span>{{installInfo.containerFileSize}}KB</span>
              </li>
              <li>
                <span> 厂家： </span>
                <span>{{installInfo.containerFileFactory}}</span>
              </li>
              <li>
                <span> 操作系统： </span>
                <span>{{installInfo.containerFileOperatingSystem}}</span>
              </li>
              <li>
                <span>架构： </span>
                <span>{{installInfo.containerFileSchema}}</span>
              </li>
            </ul>
          </div>
        </div>
        <el-table :data="installInfo.containerTaskDetailDTOList" style="width: 100%" fit :max-height="maxHeight" border stripe size="mini" highlight-current-row
          :header-cell-style="{ background: '#e5e5e5', color: '#000' }">
          <el-table-column prop="nodeId" label="设备标识" />
          <el-table-column prop="deviceModel" label="设备型号" />
          <el-table-column prop="containerName" label="容器名称">
          </el-table-column>
          <el-table-column prop="containerIndex" label="容器下标">
          </el-table-column>
          <el-table-column prop="containerIp" label="容器IP地址" />
          <el-table-column prop="containerMemoryTotal" label="分配内存（MB）" />
          <el-table-column prop="containerStorageTotal" label="存储空间（MB）" />
          <el-table-column prop="containerCpuPeriod" label="CPU的运行周期(μs)" />
          <el-table-column prop="containerCpuQuota" label="CPU运行时间(μs)" />
          <el-table-column prop="containerHyperv" label="技术类型" />
          <el-table-column prop="containerIoPort" label="物理接口" />
          <el-table-column prop="volumes" label="卷列表">
            <template slot-scope="{ row,$index}">
              <span style="color:#409eff;cursor: pointer;" v-if="row.volumes&&row.volumes.length" @click="checkVolume(row)">查看</span>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
    <div style="text-align: right;margin-top:10px">
      <el-button type="primary" @click="prevConfig" size="small">上一步</el-button>
      <el-button type="primary" @click="nextConfig" size="small">下一步</el-button>
      <!-- <el-button type="primary" @click="nextConfig" v-if="stepsActive ==5" size="small">安装</el-button>
      <el-button type="primary" v-if="stepsActive ==6" size="small">完成</el-button> -->
      <el-button size="small" @click="onCancel">取消</el-button>
    </div>
    <el-dialog title="数据卷列表" :visible.sync="dialogVisibleVolume" top="50px" width="1000px" :close-on-click-modal="false">
      <el-table :data="volumesList" ref="deviceTableDataRef" style="width: 100%" fit  border stripe size="mini" highlight-current-row
        :header-cell-style="{ background: '#e5e5e5', color: '#000' }">
        <el-table-column prop="path" label="数据卷根目录" />
        <el-table-column prop="size" label="数据卷大小（MB）" />
        <el-table-column prop="visible" label="数据卷权限">
          <template slot-scope="{ row,$index}">
            <span v-if="row.visible==0">不可访问</span>
            <span v-if="row.visible==1">可访问</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { containerSave } from "@/api/container"

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      dialogVisibleVolume: false,
      volumesList: [],
      formInline: {},
      SelectedTableData: [],
      installInfo: {
        containerTaskDetailDTOList: []
      },
      siteList: []
    }
  },
  //监听属性 类似于data概念
  computed: {
    maxHeight() {
      var curHeight =
        window.innerHeight ||
        document.documentElement.clientHeight ||
        document.body.clientHeight;
      return curHeight - 480;
    },
  },
  //监控data中的数据变化
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created() { },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.$bus.$on('INSTALLING', data => {
      var siteIdList = []
      this.siteList = []
      this.installInfo = Object.assign({}, data)
      console.log(this.installInfo, '-0-0-0-');
      console.log("生命周期", this.installInfo);
      this.installInfo.containerTaskDetailDTOList.map(item => {
        delete item.id
        if (siteIdList.indexOf(item.sitesId) == -1) {
          siteIdList.push(item.sitesId)
          this.siteList.push(item)
        }
      })
    })
  },
  methods: {
    checkVolume(item) {
      this.volumesList = item.volumes
      this.dialogVisibleVolume = true
    },
    // 上一步
    prevConfig() {
      this.$bus.$emit('prevConfig', 1)
    },
    nextConfig() {
      this.$confirm(`您将对${this.installInfo.containerFileName}容器进行安装,请核查是否确认需要进行安装！?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // this.stepsActive += 1
        containerSave(this.installInfo).then(resp => {
          console.log(resp, 'resp');
          if (resp.code == 200) {
            this.$bus.$emit('nextConfig', 1)
            this.$bus.$emit('toDownload', resp.data)
          } else {
            // this.$message({
            //   type:'error',
            //   message:''
            // })
          }
        })
      })
    },
    onCancel() {
      this.$confirm('此操作将删除原有的数据配置, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$router.push({
          path: "/containerShop",
        })
      })
    },
    onSubmit() { }
  },
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.confirmInstallInfo {
  padding: 20px;
  position: relative;
  .left {
    width: 300px;
    background-color: red;
  }
  .right {
    position: absolute;
    left: 300px;
    top: 0;
    background-color: #ccc;
  }
}
</style>

<style lang='scss'>
.confirmInstallInfo {
  .el-aside {
    /* background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px; */
    border-right: 1px solid #e6e6e6;
    li {
      line-height: 28px;
      cursor: pointer;
    }
    li:hover {
      background-color: #e5e5e5;
    }
  }
  .el-main {
    padding: 0 10px !important;
    .header {
      line-height: 30px;
      text-align: center;
    }
    .containItem {
      // width: 19.5%;
      width: 315px;
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      padding: 15px;
      margin-bottom: 15px;
      .containItem_top {
        display: flex;
        align-items: center;
        .containItem_top_right {
          display: flex;
          align-items: center;
          justify-content: space-between;
          flex: 1;
          margin-left: 10px;
          > div {
            font-size: 14px;
            margin-right: 10px;
          }
        }
      }
      .containItem_bottom {
        ul {
          li {
            line-height: 20px;
          }
        }
      }
    }
  }
}
</style>